package com.chushouya.controller.manager.admin;


import com.chushouya.manager.dto.admin.log.LoginLogListDTO;
import com.chushouya.manager.dto.admin.log.LoginLogQueryDTO;
import com.chushouya.manager.service.admin.LoginLogService;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.chushouya.common.constant.ServiceType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = ServiceType.PLATFORM + "登录日志")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/loginLog")
public class LoginLogController {

    @Resource
    private LoginLogService loginLogService;

    @ApiOperation("分页查询登录日志")
    @GetMapping("/list")
    public Response<PageResult<LoginLogListDTO>> list(LoginLogQueryDTO query) {
        return Response.success(loginLogService.selectLoginInfoPageResult(query));
    }

    @ApiOperation("清空日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cleanBeforeDays", value = "清空N天前的数据", dataType = "Integer", paramType = "query", defaultValue = "0"),
    })
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/clean")
    public Response<Void> clean(Integer cleanBeforeDays) {
        loginLogService.clean(cleanBeforeDays);
        return Response.success();
    }
}
